#列表的常用操作
print("*************************")
name = ['Alice', 'Bob', 'Charlie', 'David']
name.index('Charlie') # 除了集合其他都可以index
name.append('Eve') # 添加元素到末尾
name.pop(2) # 删除指定参数的元素,()内无参数默认删除最后一个元素
name.remove('Bob') # 删除指定元素
print(name)
for nam in name:#遍历列表#Alice David Eve
    print(nam)
print("------------------------")
num = [1, 3, 2, 4, 5]
num.sort() # 排序从小到大
print(num)
num.reverse() # 从大到小
print(num)
print("------------------------")
# 嵌套多维列表
student = [
    ["刘亦菲","张曼玉","周杰伦"],
    ["陈奕迅","林俊杰","王力宏"],
    ["张惠妹","王菲"]
]
student[0][1] = "张学友" # 修改列表元素
print(student[0][2]) # 输出周杰伦
print("*************************")



#元组的常用操作
print("*"*20)
name = ('Alice', 'Bob', 'Charlie', 'David')
print(name,type(name))
for nam in name:
    print(nam)
# name[0] = "卡卡西"#元组不能修改元素
afc = "阿肥","阿迪","阿卡","阿妮"
print(afc,type(afc))
afcc = ("阿肥",)
print(afcc,type(afcc))#元组只有一个元素时，需要加,
print("---------------------------")
num = ("刘亦菲","女","18")#组包
name, gender, age = num#解包
print(name,gender,age)
a,b = 1,2
a,b = b,a#交换变量的值
print(a,b)
print("----------------------------")
names = ("刘亦菲","张曼玉","周杰伦")#想要修改元组中的元素，需要先将元组转换成列表
names_list  = list(names)
names_list[1]="张学友"
names_list.append("王力宏")
names_list.pop(2)
names_list.remove("刘亦菲")
print(names_list)




    

